package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.core.util.PageUtil;
import com.hbnu.system.mapper.FundsflowMapper;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.*;
import com.hbnu.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Service
public class FundsflowServiceImpl extends ServiceImpl<FundsflowMapper, Fundsflow> implements FundsflowService {

    @Autowired
    FundsConditionService fundsConditionService;
    @Autowired
    FundsflowService fundsflowService;
    @Autowired
    IPorproject_registrationService iPorproject_registrationService;
    @Autowired
    ITranproject_registrationService iTranproject_registrationService;

    @Autowired
    IUserService iUserService;
    @Autowired private IDeptService iDeptService;
    @Override
    public boolean addFundsout(Fundsflow fundsflow) {
        fundsflow.setFundsType("支出经费");
        if (StrUtil.isEmpty(fundsflow.getFundsConditionID()) || StrUtil.isBlank(fundsflow.getFundsConditionID())){
            throw new BaseException("请输入项目id!");
        }
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        FundsCondition fundsCondition = fundsConditionService.getById(fundsflow.getFundsConditionID());
        fundsflow.setProjectid(fundsCondition.getProjectid());

        return baseMapper.updateById(fundsflow)==1;
    }

    @Override
    public boolean deleteFundsout(String ID) {
        Fundsflow one = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID, ID)
                .eq(Fundsflow::getFundsType,"支出经费"));
        if (Objects.isNull(one)){
            throw new BaseException("支出经费编号有误!");
        }
        return baseMapper.deleteById(ID) == 1;
    }

    @Override
    public boolean updateFundsout(Fundsflow fundsflow) {
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        if(!fundsflow.getFundsType().equals("支出经费")){
            throw new BaseException("经费种类错误");
        }
        return baseMapper.updateById(fundsflow)==1;
    }

    @Override
    public IPage<Fundsflow> pageCondition(SearchPageDTO searchPageDTO) {
        IPage<Fundsflow> page = PageUtil.getPage(searchPageDTO.getPageNum(), searchPageDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsType,"支出经费");
        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
//        IPage<PaperVO> taskVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        List<Fundsflow> records = fundsflowIPage.getRecords();
        List<Fundsflow> fundsflowS = new ArrayList<>();

        int count = 1;
        int start = searchPageDTO.getPageSize() * (searchPageDTO.getPageNum()-1)+1;
        int end = searchPageDTO.getPageNum() * searchPageDTO.getPageSize();
//        records.forEach(record->{
//            if (count >= start && count <= end){
//                PaperS.add(this.getPaper(record.getPaperID()));
//            }
//        });
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
                fundsflowS.add(this.getFundsflow(record.getFundsflowID()));
            }
            count += 1;
        }


        Collections.reverse(fundsflowS);
        fundsflowIPage.setRecords(fundsflowS);
        fundsflowIPage.setTotal(fundsflowS.size());
        return fundsflowIPage;
    }

    @Override
    public Fundsflow getFundsflow(String fundsflowID) {
        Fundsflow fundsflow = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID, fundsflowID)
                .eq(Fundsflow::getFundsType,"支出经费"));
        if(Objects.isNull(fundsflow)){
            throw new BaseException("经费流动编号异常!未查找到该经费");
        }
        return fundsflow;
    }

    @Override
    public Boolean ReCommitFundsout(String id) {
        Fundsflow fundsflow = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID,id));
        if(Objects.isNull(fundsflow)){
            throw new BaseException("经费流动编号有误!");
        }
        if(!fundsflow.getFundsType().equals("经费支出")&& !fundsflow.getStatus().equals("支出退回")&& !fundsflow.getStatus().equals("支出审核")){
            throw new BaseException("该支出经费不适用于该阶段!");
        }
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        fundsflow.setStatus("支出审核");
        fundsflow.setReason("");
        return baseMapper.updateById(fundsflow)==1;
    }
    @Override
    public Boolean schoolCheckfundsoutPass(String PID) {
        Fundsflow fundsflow = fundsflowService.getFundsflow(PID);
        if (Objects.isNull(fundsflow)){
            throw new BaseException("该经费流动编号有误!");
        }
        if(!fundsflow.getStatus().equals("支出审核")){
            throw new BaseException("该经费流动状态不处于该环节!");
        }
        fundsflow.setStatus("支出审核通过");
        FundsCondition fundsCondition = fundsConditionService.getFundsCondition(fundsflow.getFundsConditionID());
        fundsCondition.setOutputFunds(fundsflow.getOutputFunds()+fundsCondition.getOutputFunds());
        fundsConditionService.updateById(fundsCondition);
        return baseMapper.updateById(fundsflow) == 1;
    }

    @Override
    public Boolean schoolCheckfundsoutBack(CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Fundsflow fundsflow= fundsflowService.getFundsflow(id);
        if (Objects.isNull(fundsflow)){
            throw new BaseException("该经费流动编号有误!");
        }
        if(!fundsflow.getStatus().equals("支出审核")){
            throw new BaseException("该经费流动状态不处于该环节!");
        }
        fundsflow.setStatus("支出被校级退回");
        fundsflow.setReason(checkBackDTO.getReason());
        return baseMapper.updateById(fundsflow) == 1;
    }
    @Override
    public IPage<Fundsflow> userGetRelateFundsout(UserDTO userDTO){
        if(Objects.isNull(iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName,userDTO.getName())))){
            throw new BaseException("用户姓名有误!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getHead, userDTO.getName())
                .eq(Fundsflow::getFundsType,"支出经费");
        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
                fundsflowList.add(this.getFundsflow(record.getFundsflowID()));
//                paperList.add(this.getPaperVO(record.getPaperID()));
            }
            count += 1;
        }

//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }

    @Override
    public IPage<Fundsflow> schoolUserGetfundsout(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
//                .eq(Paper::getDept,deptName)
                .and(wrapper1 -> wrapper1.eq(Fundsflow::getStatus,"支出审核"));

        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                fundsflowList.add(this.getFundsflow(record.getFundsflowID()));
            }
            count += 1;
        }
//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }

    @Override
    public IPage<Fundsflow> schoolUserGetfundsoutover(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
//                .eq(Paper::getDept,deptName)
                .eq(Fundsflow::getStatus,"支出审核通过")
                .or().eq(Fundsflow::getStatus,"支出被校级退回");

        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                fundsflowList.add(this.getFundsflow(record.getFundsflowID()));
            }
            count += 1;
        }

//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }

    @Override
    public boolean addFundsarrival(Fundsflow fundsflow) {
        fundsflow.setFundsType("到账经费");
        if (StrUtil.isEmpty(fundsflow.getFundsConditionID()) || StrUtil.isBlank(fundsflow.getFundsConditionID())){
            throw new BaseException("请输入项目id!");
        }
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        return baseMapper.updateById(fundsflow)==1;
    }

    @Override
    public boolean deleteFundsarrival(String ID) {
        Fundsflow one = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID, ID)
                .eq(Fundsflow::getFundsType,"到账经费"));
        if (Objects.isNull(one)){
            throw new BaseException("到账经费编号有误!");
        }
        return baseMapper.deleteById(ID) == 1;
    }

    @Override
    public boolean updateFundsarrival(Fundsflow fundsflow) {
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        if(!fundsflow.getFundsType().equals("到账经费")){
            throw new BaseException("经费种类错误");
        }
        return baseMapper.updateById(fundsflow)==1;
    }

    @Override
    public IPage<Fundsflow> pageConditionarrival(SearchPageDTO searchPageDTO) {
        IPage<Fundsflow> page = PageUtil.getPage(searchPageDTO.getPageNum(), searchPageDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsType,"到账经费");
        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
//        IPage<PaperVO> taskVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        List<Fundsflow> records = fundsflowIPage.getRecords();
        List<Fundsflow> fundsflowS = new ArrayList<>();

        int count = 1;
        int start = searchPageDTO.getPageSize() * (searchPageDTO.getPageNum()-1)+1;
        int end = searchPageDTO.getPageNum() * searchPageDTO.getPageSize();
//        records.forEach(record->{
//            if (count >= start && count <= end){
//                PaperS.add(this.getPaper(record.getPaperID()));
//            }
//        });
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
                fundsflowS.add(this.getFundsflow(record.getFundsflowID()));
            }
            count += 1;
        }


//        Collections.reverse(fundsflowS);
        fundsflowIPage.setRecords(fundsflowS);
        fundsflowIPage.setTotal(fundsflowS.size());
        return fundsflowIPage;
    }

    @Override
    public Fundsflow getFundsarrivalflow(String fundsflowID) {
        Fundsflow fundsflow = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID, fundsflowID)
                .eq(Fundsflow::getFundsType,"到账经费"));
        if(Objects.isNull(fundsflow)){
            throw new BaseException("经费流动编号异常!未查找到该经费");
        }
        return fundsflow;
    }

    @Override
    public Boolean ReCommitFundsarrival(String id) {
        Fundsflow fundsflow = super.getOne(Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getFundsflowID,id));
        if(Objects.isNull(fundsflow)){
            throw new BaseException("经费流动编号有误!");
        }
        if(!fundsflow.getFundsType().equals("到账经费")&& !fundsflow.getStatus().equals("到账退回")&&!fundsflow.getStatus().equals("到账审核")){
            throw new BaseException("该到账经费不适用于该阶段!");
        }
        if (StrUtil.isEmpty(fundsflow.getProjectName()) || StrUtil.isBlank(fundsflow.getProjectName())){
            throw new BaseException("请输入项目名称!");
        }
        if (StrUtil.isEmpty(fundsflow.getUnit()) || StrUtil.isBlank(fundsflow.getUnit())){
            throw new BaseException("请输入承担单位!");
        }
        if (StrUtil.isEmpty(fundsflow.getHead()) || StrUtil.isBlank(fundsflow.getHead())){
            throw new BaseException("请输入负责人!");
        }
        fundsflow.setStatus("到账审核");
        fundsflow.setReason("");
        return baseMapper.updateById(fundsflow)==1;
    }

    @Override
    public Boolean schoolCheckfundsarrivalPass(String PID) {
        Fundsflow fundsflow = fundsflowService.getFundsarrivalflow(PID);
        if (Objects.isNull(fundsflow)){
            throw new BaseException("该经费流动编号有误!");
        }
        if(!fundsflow.getStatus().equals("到账审核")){
            throw new BaseException("该经费流动状态不处于该环节!");
        }
        fundsflow.setStatus("到账审核通过");
        FundsCondition fundsCondition = fundsConditionService.getFundsCondition(fundsflow.getFundsConditionID());
        fundsCondition.setArrivingFunds(fundsflow.getArrivingFunds()+fundsCondition.getArrivingFunds());
        fundsConditionService.updateById(fundsCondition);
        Porproject_registration pr = iPorproject_registrationService.getById(fundsflow.getProjectid());
//        if(!Objects.isNull(pr)&&!StrUtil.isBlank(pr.getArrivingFunds())){
//            pr.setArrivingFunds(fundsflow.getArrivingFunds()+pr.getArrivingFunds());
//            iPorproject_registrationService.updateById(pr);
//        }else if(!Objects.isNull(pr)&&StrUtil.isBlank(pr.getArrivingFunds())){
//            pr.setArrivingFunds(fundsflow.getArrivingFunds());
//            iPorproject_registrationService.updateById(pr);
//        }
        Tranproject_registration tr = iTranproject_registrationService.getById(fundsflow.getProjectid());
        if(!Objects.isNull(tr)&&!StrUtil.isBlank(tr.getArrivingFunds())){
            tr.setArrivingFunds(fundsflow.getArrivingFunds()+tr.getArrivingFunds());
            iTranproject_registrationService.updateById(tr);
        }
        else if(!Objects.isNull(tr)&&StrUtil.isBlank(tr.getArrivingFunds())){
            tr.setArrivingFunds(fundsflow.getArrivingFunds()+tr.getArrivingFunds());
            iTranproject_registrationService.updateById(tr);
        }
        return baseMapper.updateById(fundsflow) == 1;
    }

    @Override
    public Boolean schoolCheckfundsarrivalBack(CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Fundsflow fundsflow= fundsflowService.getFundsflow(id);
        if (Objects.isNull(fundsflow)){
            throw new BaseException("该经费流动编号有误!");
        }
        if(!fundsflow.getStatus().equals("到账审核")){
            throw new BaseException("该经费流动状态不处于该环节!");
        }
        fundsflow.setStatus("到账被校级退回");
        fundsflow.setReason(checkBackDTO.getReason());
        return baseMapper.updateById(fundsflow) == 1;
    }

    @Override
    public IPage<Fundsflow> userGetRelateFundsarrival(UserDTO userDTO) {
        if(Objects.isNull(iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName,userDTO.getName())))){
            throw new BaseException("用户姓名有误!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
                .eq(Fundsflow::getHead, userDTO.getName())
                .eq(Fundsflow::getFundsType,"到账经费");
        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
                fundsflowList.add(this.getFundsarrivalflow(record.getFundsflowID()));
//                paperList.add(this.getPaperVO(record.getPaperID()));
            }
            count += 1;
        }

//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }

    @Override
    public IPage<Fundsflow> schoolUserGetfundsarrival(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
//                .eq(Paper::getDept,deptName)
                .and(wrapper1 -> wrapper1.eq(Fundsflow::getStatus,"到账审核"));

        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                fundsflowList.add(this.getFundsarrivalflow(record.getFundsflowID()));
            }
            count += 1;
        }
//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }

    @Override
    public IPage<Fundsflow> schoolUserGetfundsarrivalover(UserDTO userDTO) {
        User one = iUserService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, userDTO.getName()));
        if(Objects.isNull(one)){
            throw new BaseException("用户姓名有误!");
        }
        String dept = one.getDept();
        String deptName = iDeptService.getById(dept).getDeptName();
        String role = one.getRole();
        if(!role.equals("19190251173")){
            throw new BaseException("该用户权限不为校级审核员!");
        }
        IPage<Fundsflow> page = PageUtil.getPage(userDTO.getPageNum(), userDTO.getPageSize());
        LambdaQueryWrapper<Fundsflow> wrapper = Wrappers.lambdaQuery(Fundsflow.class)
//                .eq(Paper::getDept,deptName)
                .eq(Fundsflow::getStatus,"到账审核通过")
                .or().eq(Fundsflow::getStatus,"到账被校级退回");

        IPage<Fundsflow> fundsflowIPage = baseMapper.selectPage(page, wrapper);
        List<Fundsflow> records = fundsflowIPage.getRecords();
//        IPage<PaperVO> paperVOIPage = iBeanService.copyPageProperties(paperIPage, PaperVO.class);
        ArrayList<Fundsflow> fundsflowList = new ArrayList<>();

        //对分页的设置
        int count = 1;
        int start = userDTO.getPageSize() * (userDTO.getPageNum()-1)+1;
        int end = userDTO.getPageNum() * userDTO.getPageSize();
        Collections.reverse(records);
        for (Fundsflow record:records) {
            if (count >= start && count <= end){
//                this.getPaper(record.getPaperID())
                fundsflowList.add(this.getFundsarrivalflow(record.getFundsflowID()));
            }
            count += 1;
        }

//        Collections.reverse(fundsflowList);
        fundsflowIPage.setRecords(fundsflowList);
        fundsflowIPage.setTotal(records.size());

        return fundsflowIPage;
    }
}
